//
//  BDFridentTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/1/5.
//  Copyright © 2017年 niusaibing. All rights reserved.
//

#import "BDFridentTableViewCell.h"
#import "BDApplyFriendsModel.h"
@implementation BDFridentTableViewCell

-(UIImageView *)avatarImage{
    if (!_avatarImage) {
        _avatarImage = [[UIImageView alloc]init];
        _avatarImage.layer.masksToBounds = YES;
        _avatarImage.layer.cornerRadius = 25;
        [self.contentView addSubview:_avatarImage];
    }
    return _avatarImage;
}
-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#1c1c1c"];
        _nameLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:_nameLabel];
    }
    return _nameLabel;
}

- (UILabel *)applyCountLabel{
    if (!_applyCountLabel) {
        _applyCountLabel = [[UILabel alloc]init];
        _applyCountLabel.textColor = [UIColor whiteColor];
        _applyCountLabel.backgroundColor = [UIColor redColor];
        _applyCountLabel.font = [UIFont systemFontOfSize:7];
        _applyCountLabel.textAlignment = NSTextAlignmentCenter;
        _applyCountLabel.layer.cornerRadius = 7.5;
        _applyCountLabel.layer.masksToBounds = YES;
        [self.contentView addSubview:_applyCountLabel];
    }
    return _applyCountLabel;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.avatarImage.size = CGSizeMake(50, 50);
    self.avatarImage.left =10;
    self.avatarImage.centerY = self.contentView.centerY;
    
    [self.nameLabel sizeToFit];
    self.nameLabel.left = self.avatarImage.right + 10;
    self.nameLabel.centerY = self.avatarImage.centerY;
    
    self.applyCountLabel.size = CGSizeMake(15, 15);
    self.applyCountLabel.centerY = self.avatarImage.top;
    self.applyCountLabel.centerX = self.avatarImage.right;
}

@end

@implementation BDNewFridentTableViewCell

- (void)configeWithModel:(id)model clickButtonClick:(void(^)())clickBlock{
    BDApplyFriendsModel *applyModel = model;
    self.nameLabel.text = applyModel.nickname;
//    self.messageLabel.text = applyModel.message;
    if (applyModel.applyMode.integerValue == BDApplyFriendModeDefault) {
        self.messageLabel.text = ASLocalizedString(@"对方请求添加你为朋友");
    }else if (applyModel.applyMode.integerValue == BDApplyFriendModeAgree) {
        self.messageLabel.text = ASLocalizedString(@"已经同意对方的好友请求");
    }else if (applyModel.applyMode.integerValue == BDApplyFriendModeDelete) {
        self.messageLabel.text = ASLocalizedString(@"对方已经把你从好友中删除");
    }else if (applyModel.applyMode.integerValue == BDApplyFriendModeReAdd) {
        self.messageLabel.text = ASLocalizedString(@"已经重新发送添加请求");
    }
    
    if (applyModel.applyMode.integerValue == 0) {
        [self.addButton setTitle:ASLocalizedString(@"同意")forState:UIControlStateNormal];
        self.addButton.backgroundColor = KBDColorBlue;
        self.addButton.size = CGSizeMake(63, 32);
        self.addButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.addButton.userInteractionEnabled = YES;
    }else if (applyModel.applyMode.integerValue == 1) {
        self.addButton.backgroundColor = [UIColor clearColor];
        self.addButton.userInteractionEnabled = NO;
        [self.addButton setTitle:ASLocalizedString(@"已添加")forState:UIControlStateNormal];
        [self.addButton setTitleColor:[UIColor colorWithHexString:@"#808080"] forState:UIControlStateNormal];
        self.addButton.titleLabel.font = [UIFont systemFontOfSize:13];
        self.addButton.size = CGSizeMake([[self.addButton titleForState:UIControlStateNormal] widthWithFont:self.addButton.titleLabel.font], self.addButton.titleLabel.font.pointSize+1);
        self.addButton.userInteractionEnabled = NO;
    }else if (applyModel.applyMode.integerValue == 2) {
        [self.addButton setTitle:ASLocalizedString(@"重新添加")forState:UIControlStateNormal];
        self.addButton.backgroundColor = KBDColorBlue;
        self.addButton.size = CGSizeMake(63, 32);
        self.addButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.addButton.userInteractionEnabled = YES;
    }else if (applyModel.applyMode.integerValue == 3) {
        self.addButton.backgroundColor = [UIColor clearColor];
        self.addButton.userInteractionEnabled = NO;
        [self.addButton setTitle:ASLocalizedString(@"已添加")forState:UIControlStateNormal];
        [self.addButton setTitleColor:[UIColor colorWithHexString:@"#808080"] forState:UIControlStateNormal];
        self.addButton.titleLabel.font = [UIFont systemFontOfSize:13];
        self.addButton.size = CGSizeMake([[self.addButton titleForState:UIControlStateNormal] widthWithFont:self.addButton.titleLabel.font], self.addButton.titleLabel.font.pointSize+1);
        self.addButton.userInteractionEnabled = NO;
    }
    [[self.addButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (clickBlock) {
            clickBlock();
        }
    }];
}

-(UIImageView *)avatarImage{
    if (!_avatarImage) {
        _avatarImage = [[UIImageView alloc]init];
        _avatarImage.image = [UIImage imageNamed:@"avatar"];
        [self.contentView addSubview:_avatarImage];
    }
    
    return _avatarImage;
}
-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = KBDNameColor;
        _nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_nameLabel];
    }
    return _nameLabel;
}

-(UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = [UIFont systemFontOfSize:12];
        _messageLabel.textColor = kBDTimeColor;
        [self.contentView addSubview:_messageLabel];
    }
    return _messageLabel;
}

-(UIButton *)addButton{
    if (!_addButton) {
        _addButton = [[UIButton alloc]init];
        _addButton.layer.cornerRadius = 6;
        _addButton.backgroundColor = KBDColorBlue;
//        _addButton.layer.borderWidth = 0.5;
        [_addButton setTitle:ASLocalizedString(@"同意")forState:UIControlStateNormal];
        [self.contentView addSubview:_addButton];
    }
    return _addButton;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.avatarImage.size = CGSizeMake(45, 45);
    self.avatarImage.left = 10;
    self.avatarImage.centerY = self.height / 2.0;
    self.avatarImage.layer.masksToBounds = YES;
    self.avatarImage.layer.cornerRadius = self.avatarImage.width / 2.0;
    
    self.nameLabel.font = [UIFont systemFontOfSize:17];
    self.nameLabel.textColor = [UIColor colorWithHexString:@"#1c1c1c"];
    [self.nameLabel sizeToFit];
    self.nameLabel.left = self.avatarImage.right + 10;
    self.nameLabel.bottom = self.avatarImage.centerY - 5;
    
    self.messageLabel.font = [UIFont systemFontOfSize:15];
    self.messageLabel.textColor = [UIColor colorWithHexString:@"#767676"];
    [self.messageLabel sizeToFit];
    self.messageLabel.left = self.nameLabel.left;
    self.messageLabel.top = self.nameLabel.bottom + 15;
    
    self.addButton.right = self.width - 10;
    self.addButton.centerY = self.height / 2.0;
}

@end
